//
//  LSZNoticeNameViewController.m
//  JKFuYinProject
//
//  Created by 九酷 on 2018/9/10.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LSZNoticeNameViewController.h"

@interface LSZNoticeNameViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSArray * arrayName;
}
@property(nonatomic,strong) UITableView * tableViewNoticeName;
@end

@implementation LSZNoticeNameViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.tableViewNoticeName reloadData];
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    NSNotification *notification =[NSNotification notificationWithName:@"ANewMessage" object:nil userInfo:nil];
    [[NSNotificationCenter defaultCenter] postNotification:notification];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"ANewMessage" object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableViewNoticeName registerClass:[LSZNoticeTableViewCell class] forCellReuseIdentifier:@"LSZNoticeTableViewCell"];
    arrayName = @[@"系统消息",@"动态消息"];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return arrayName.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height = [LSZSpecialPackaging initWithReturnsthesizeOf:70 :5];
    return height;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.001;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZNoticeTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZNoticeTableViewCell" forIndexPath:indexPath];
    cell.imageViewIcon.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",arrayName[indexPath.row]]];
    cell.labelTitle.text = arrayName[indexPath.row];
    cell.labelNumber.hidden = NO;
    cell.labelExplain.text = @"新信息通知";
    cell.labelTime.hidden = YES;

    if (indexPath.row == 0) {
        NSInteger A = [[_UserM sys_not_read] integerValue];
        if (A == 0) {
            cell.labelNumber.hidden = YES;
        }else{
            cell.labelNumber.hidden = NO;
            cell.labelNumber.text = [NSString stringWithFormat:@"%ld",(long)A];
        }
    }else{
        NSInteger B = [[_UserM msg_not_read] integerValue];
        if (B == 0) {
            cell.labelNumber.hidden = YES;
        }else{
            cell.labelNumber.hidden = NO;
            cell.labelNumber.text = [NSString stringWithFormat:@"%ld",(long)B];
        }
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0){
        LSZSystemNotificationDetailsVC * vc = [[LSZSystemNotificationDetailsVC alloc]init];
        vc.type = @"1";
        vc.kind = @"1";
        vc.tag = @"0";
        [self.navigationController pushViewController:vc animated:YES];
        return;
    }else{
        if ([[_UserM usercode] isEqualToString:@""]) {
            pushAccLoginVC;
        }else{
            LSZParentClassNotificationDetailsVC * vc = [[LSZParentClassNotificationDetailsVC alloc]init];
            vc.stringTitle = @"动态通知详情";
            vc.type = @"1";
            vc.kind = @"2";
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}
-(UITableView *)tableViewNoticeName
{
    if (_tableViewNoticeName == nil) {
        _tableViewNoticeName = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-44) style:UITableViewStyleGrouped];
        _tableViewNoticeName.delegate = self;
        _tableViewNoticeName.dataSource = self;
        _tableViewNoticeName.separatorColor = divider;
        _tableViewNoticeName.estimatedRowHeight =0;
        _tableViewNoticeName.estimatedSectionFooterHeight =0;
        _tableViewNoticeName.estimatedSectionHeaderHeight =0;
        _tableViewNoticeName.separatorInset = UIEdgeInsetsMake(0, 20, 0, 20);
        [self.view addSubview:_tableViewNoticeName];
    }
    return _tableViewNoticeName;
}


@end
